package appapi.service.impl;

import appapi.Request.Basic.DictionaryPageReq;
import appapi.Request.Basic.DictionaryReq;
import appapi.Request.ModulelistReq;
import appapi.dao.DictionaryMapper;
import appapi.entity.Zhongjiao.DictionaryDto;
import appapi.entity.auth.ModulelistEntity;
import appapi.service.IDictionaryService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author djq
 * @date 2023/5/25 14:00
 * @description:
 */
@Component
public class DictionaryServiceImpl implements IDictionaryService {
    @Resource
    private DictionaryMapper dictionaryMapper;
    @Override
    public List<Map<String, Object>> selectDicTypeList(String dicType) {

        return dictionaryMapper.selectDicType(dicType);
    }
    @Override
    public PageInfo<DictionaryDto> Page(DictionaryPageReq req){
        if (ObjectUtils.allNotNull(req.getCurrPage(), req.getPageSize())){
            PageHelper.startPage(req.getCurrPage(), req.getPageSize());
        }
        String json = JSON.toJSONString(req);
        DictionaryReq dataReq = JSON.parseObject(json, new TypeReference<DictionaryReq>() {
        });
        List<DictionaryDto> list = dictionaryMapper.queryList(dataReq);
        PageInfo pageInfo = new PageInfo(list);

        return pageInfo;
    }

    @Override
    public int AddInfo(DictionaryDto dto){
        return dictionaryMapper.insert(dto);
    }

    @Override
    public int EditInfo(DictionaryDto dto){
        return dictionaryMapper.updateByPrimaryKeySelective(dto);
    }

    @Override
    public int DeleteInfo(Long dictId){
        return dictionaryMapper.deleteByPrimaryKey(dictId);
    }

    @Override
    public DictionaryDto GetDetail(Long dictId){
        return dictionaryMapper.selectByPrimaryKey(dictId);
    }

    @Override
    public List<DictionaryDto> GetList(DictionaryReq req){
        return dictionaryMapper.queryList(req);
    }

    @Override
    public int Count(DictionaryDto dto){
        return dictionaryMapper.queryCount(dto);
    }

    @Override
    public List<String> GetTypeList(){
        return dictionaryMapper.queryTypeList();
    }

    @Override
    public List<DictionaryDto> getList(DictionaryPageReq req) {
        String json = JSON.toJSONString(req);
        DictionaryReq dataReq = JSON.parseObject(json, new TypeReference<DictionaryReq>() {
        });
        List<DictionaryDto> list = dictionaryMapper.queryList(dataReq);
        return list;
    }

}
